//
//  SRAttentionViewController.m
//  Fitness
//
//  Created by SunZhongyuan on 2018/6/5.
//  Copyright © 2018年 SunZhongyuan. All rights reserved.
//

#import "SRAttentionViewController.h"
#import "SRAttentionCollectionViewCell.h"

@interface SRAttentionViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property(nonatomic, strong) UILabel *hotRecommendLabel;
@property(nonatomic, strong) UICollectionView *mainCollectionView;

@end

@implementation SRAttentionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.hotRecommendLabel];
    [self.view addSubview:self.mainCollectionView];
}

#pragma mark - collectionView delegate

// 每个section的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 9;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SRAttentionCollectionViewCell *cell = (SRAttentionCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"SRAttentionCollectionViewCell" forIndexPath:indexPath];
    cell.botlabel.text = @"MICU小明";
    cell.topImage.image = [UIImage imageNamed:@"default_avater"];
    return cell;
}

// 设置每个item的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(0.23*kScreenWidth, 0.23*kScreenWidth);
}

// 设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}

// 点击item方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"hhahahhahahh");
}


#pragma mark - getters

- (UILabel *)hotRecommendLabel {
    if (_hotRecommendLabel == nil) {
        _hotRecommendLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.03*kScreenWidth, 0, kScreenWidth, 0.06*kScreenHeight)];
        _hotRecommendLabel.textAlignment = NSTextAlignmentLeft;
        _hotRecommendLabel.text = @"热门推荐";
        _hotRecommendLabel.font = font(15);
        _hotRecommendLabel.textColor = [UIColor blackColor];
    }
    return _hotRecommendLabel;
}

- (UICollectionView *)mainCollectionView {
    if (_mainCollectionView == nil) {
        // 1.初始化layout
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        // 设置collectionView滚动方向
        [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        // 2.初始化collectionView
        _mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.hotRecommendLabel.frame), kScreenWidth, 0.15*kScreenHeight) collectionViewLayout:layout];
        _mainCollectionView.backgroundColor = [UIColor clearColor];
        // 3.注册collectionViewCell
        [_mainCollectionView registerClass:[SRAttentionCollectionViewCell class] forCellWithReuseIdentifier:@"SRAttentionCollectionViewCell"];
        //4.设置代理
        _mainCollectionView.delegate = self;
        _mainCollectionView.dataSource = self;
        _mainCollectionView.showsHorizontalScrollIndicator = NO;
        _mainCollectionView.bounces = NO;
    }
    return _mainCollectionView;
}


@end
